#version 330 core

uniform sampler2D yTexture;
uniform sampler2D uTexture;
uniform sampler2D vTexture;

in vec2 texCoord;
out vec4 fragColor;

void main() {
    vec3 YUV;
    YUV.x = texture(yTexture, texCoord).r;
    YUV.y = texture(uTexture, texCoord).r;
    YUV.z = texture(vTexture, texCoord).r;

    vec3 RGB;
    RGB.r = YUV.x + 1.13983 * (YUV.z - 0.5);
    RGB.g = YUV.x - 0.39465 * (YUV.y - 0.5) - 0.58060 * (YUV.z - 0.5);
    RGB.b = YUV.x + 2.03211 * (YUV.y - 0.5);

    // 确保RGB值在0到1之间
    RGB = clamp(RGB, 0.0, 1.0);

    // 输出RGB颜色
    fragColor = vec4(RGB, 1.0);
}
